from exts import db
from datetime import datetime


class User(db.Model):
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    email = db.Column(db.String(50), nullable=False)
    username = db.Column(db.String(50), nullable=False)
    password = db.Column(db.String(100), nullable=False)


class LoginLog(db.Model):
    __tablename__ = 'loginlog'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(50), nullable=False)
    login_time = db.Column(db.DateTime, default=datetime.now)


class WeekReport(db.Model):
    __tablename__ = 'weekreport'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    # 项目编号
    project_num  = db.Column(db.String(20),nullable=False)
    # 工作描述
    taskdescription = db.Column(db.Text, nullable=False)
    # 创建时间
    create_time = db.Column(db.DateTime, default=datetime.now)



# sale_m = db.Table('sale_m',
#     db.Column('sf_id', db.Integer, db.ForeignKey('staff.id'),primary_key=True),
#     db.Column('p_id', db.Integer, db.ForeignKey('pronum.id'),primary_key=True)
# )
#
#
# tech_m = db.Table('tech_m',
#     db.Column('sf_id', db.Integer, db.ForeignKey('staff.id'),primary_key=True),
#     db.Column('p_id', db.Integer, db.ForeignKey('pronum.id'),primary_key=True)
# )

class ProNum(db.Model):
    __tablename__ = 'pronum'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    project_num = db.Column(db.String(20), nullable=False)
    # 项目名称
    pro_name = db.Column(db.String(100), nullable=False)
    # 客户单位
    custunit = db.Column(db.String(10), nullable=False)
    # 销售负责人
    saleshead = db.Column(db.String(20), nullable=False)
    # saleshead_id = db.Column(db.Integer, db.ForeignKey('staff.id'))
    # 售前（技术）负责人
    # techhead_id = db.Column(db.Integer, db.ForeignKey('staff.id'))
    techhead = db.Column(db.String(20), nullable=False)

    # 研发负责人
    develophead = db.Column(db.String(20), nullable=False)
    # develophead_id = db.Column(db.Integer, db.ForeignKey('staff.id'))
    beizhu = db.Column(db.Text, nullable=True)

    # saleshead = db.relationship('Staff', secondary='sale_m', backref=db.backref('sale'))
    # techhead = db.relationship('Staff', secondary='tech_m', backref=db.backref('tech'))
    # techhead = db.relationship('Staff', backref=db.backref('staffs1'))
    # develophead = db.relationship('Staff', backref=db.backref('staffs'))


class Staff(db.Model):
    __tablename__ = 'staff'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    staff_num = db.Column(db.String(20), nullable=False)
    staff_name = db.Column(db.String(20), nullable=False)
    staff_duty = db.Column(db.String(30), nullable=False)
    depart = db.Column(db.String(40), nullable=False)
    # password列用于后期使用staff表进行登录
    password = db.Column(db.String(100),nullable=True)




class CustUnit(db.Model):
    __tablename__ = 'custunit'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    custunit_name = db.Column(db.String(100), nullable=False)


class Depart(db.Model):
    __tablename__ = 'depart'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    depart_name = db.Column(db.String(40), nullable=False)
    # 这里暂时设置一个部门负责人，用于后期权限管理
    depart_header = db.Column(db.String(10), nullable=False) # 这里后期版本改动可以使用外键


class Duty(db.Model):
    __tablename__ = 'duty'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    duty_name = db.Column(db.String(100), nullable=False)
    # 加入对职务内容的描述
    duty_desc = db.Column(db.Text)